package com.cn.goodsadmin.controller;


import com.cn.goodsadmin.po.FareTemlatesPageInfo;
import com.cn.goodsadmin.po.FareTemplateInfo;
import com.cn.goodsadmin.service.FareTemplateService;
import com.cn.goodsadmin.util.ErrorMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//@CrossOrigin(origins = {"http://10.10.10.143:8020"}, maxAge = 3600)
@CrossOrigin(origins = "*", maxAge = 3600)
@Controller
public class TemplateController {

    @Autowired
    FareTemplateService fareTemplateService;


    @LoginRequired
    @RequestMapping(value = "/addfaretemplate", method = RequestMethod.POST, produces = "application/json;charset=utf-8",
            consumes = "application/json;charset=utf-8")
    @ResponseBody//表示返回的是个json对象会经过配置文件转换
    public SupplyMap addFareTemplate(@RequestBody FareTemplateInfo fareTemplateInfo){
        SupplyMap supplyMap=new SupplyMap();
        try{
            fareTemplateService.addFareTemplate(fareTemplateInfo);
        }catch (Exception e){
            supplyMap.setEorrInfo(ErrorMsg.STATUS_DATABASE_ERROR,ErrorMsg.MSG_DATABASE_ERROR);
        }
        return supplyMap;
    }

    @LoginRequired
    @RequestMapping(value = "/getfaretemplate", method = RequestMethod.GET,params = {"pageindex", "pagesize","appid"})
    @ResponseBody//表示返回的是个json对象会经过配置文件转换
    public SupplyMap getFareTemplate(int pageindex,int pagesize,int appid){
        SupplyMap supplyMap=new SupplyMap();
        try{
            FareTemlatesPageInfo fareTemlatesPageInfo=fareTemplateService.findFareTempInfoByAppid(pageindex,pagesize,appid);
            supplyMap.put("pageinfo",fareTemlatesPageInfo);
        }catch (Exception e){
            supplyMap.setEorrInfo(ErrorMsg.STATUS_DATABASE_ERROR,ErrorMsg.MSG_DATABASE_ERROR);
        }
        return supplyMap;
    }


    @LoginRequired
    @RequestMapping(value = "/deletefaretemplate", method = RequestMethod.POST, produces = "application/json;charset=utf-8",
            consumes = "application/json;charset=utf-8")
    @ResponseBody//表示返回的是个json对象会经过配置文件转换
    public SupplyMap deleteFareTemplate(@RequestBody FareTemplateInfo fareTemplateInfo){
        SupplyMap supplyMap=new SupplyMap();
        try{
            fareTemplateService.deleteFareTemplate(fareTemplateInfo);
        }catch (Exception e){
            supplyMap.setEorrInfo(ErrorMsg.STATUS_DATABASE_ERROR,ErrorMsg.MSG_DATABASE_ERROR);
        }
        return supplyMap;
    }

    //updatefaretemplate

    @LoginRequired
    @RequestMapping(value = "/updatefaretemplate", method = RequestMethod.POST, produces = "application/json;charset=utf-8",
            consumes = "application/json;charset=utf-8")
    @ResponseBody//表示返回的是个json对象会经过配置文件转换
    public SupplyMap updateFareTemplate(@RequestBody FareTemplateInfo fareTemplateInfo){
        SupplyMap supplyMap=new SupplyMap();
        try{
            fareTemplateService.updateFareTemplate(fareTemplateInfo);
        }catch (Exception e){
            supplyMap.setEorrInfo(ErrorMsg.STATUS_DATABASE_ERROR,ErrorMsg.MSG_DATABASE_ERROR);
        }
        return supplyMap;
    }

}
